@extends('layouts.admin')
@section('title') @parent 商品管理 @stop
@section('page_title')@parent
修改商品
@show
@section('breadcrumb')@parent
{{ Breadcrumbs::render('product-edit') }}
@show
@section('content')
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">修改商品</h3>
                
            </div><!-- /.box-header -->
            <form fole="form" method="post" action="{{ route('admin.product.edit',['id'=>$pro->id]) }}" enctype="multipart/form-data">
            <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
            <div class="box-body">
                <div class="form-group">
                    <label for="cat_sort">分类</label>
                    <select class="form-control" name="data[category_id]" id="product_category">
                    @foreach($categories as $cat)
                    <option value="{{ $cat->id }}" @if($cat->id == $pro->category_id) selected @endif >{{ $cat->title }}</option>
                    @endforeach
                    </select>
                </div>
                <div class="form-group">
                    <label for="cat_title">标题</label>
                    <input type="text" name="data[name]" id="cat_title" placeholder="标题" value="{{ $pro->name }}" class="form-control"/>
                </div>
                <div class="form-group">
                    <label for="cat_title">库存</label>
                    <input type="number" name="data[stock]" id="cat_title" placeholder="库存" value="{{ $pro->stock }}" />
                </div>
				<div class="form-group">
                    <label for="is_recommend">是否推荐</label>
                    <input type="radio" name="data[is_recommend]" value="0" @if ( !$pro->is_recommend) checked @endif >否
					<input type="radio" name="data[is_recommend]" value="1" @if ($pro->is_recommend) checked @endif >是
                </div>
                <div class="form-group">
                    <label for="cat_title">价格</label>
                    <input type="text" name="data[price]" id="cat_title" placeholder="价格" value="{{ $pro->price }}" />元
                </div>
                <div class="form-group">
                    <label for="score_cut">积分抵扣</label>
                    <input type="text" name="data[score_cut]" id="score_cut" placeholder="如商品价格100元，可以用积分抵扣其中10元，则输入10" value="{{ $pro->score_cut }}" class="form-control"/>
                </div>
                <div class="form-group">
                    <label for="upload_pic">图片</label>
                    <input type="file" name="upload_pic" >
                    <p>
                    @if ($pro->picture!='')
                    {{ HTML::image($pro->picture, 'wg_logo', array('class'=>'pro_img')) }}
                    @endif
                    </p>
                </div>
                <div class="form-group">
                    <label for="upload_pic">商品简介</label>
                    <textarea rows="3" name="data[summary]" class="form-control">{{ $pro->summary }}</textarea>
                </div>
                <div class="form-group">
                    <label for="upload_pic">商品介绍</label>
                    <textarea cols="80" rows="10" name="attribute[introduce]" id="product_introduct" style="visibility: hidden; display: none;" class="form-control">{{ $pro->attribute?$pro->attribute->introduce:'' }}</textarea>
                </div>
					
				<div class="form-group" id="cat_spec">
                    <h3>规格</h3>
                    @foreach ($specs as $spec)
                    <div>
						<label>{{ $spec->name }}</label>
						@if ( $spec->type == Specificant::OPTION_TEXT)
						<input type="text" name="specs[{{ $spec->id }}]" value="{{ isset($pro_specs[$spec->id]) ? $pro_specs[$spec->id]->value : $spec->default }}" > 
						@elseif ($spec->type == Specificant::OPTION_SELECT)
						<select name="specs[{{ $spec->id }}]" >
							@foreach ($spec->options as $opt)
							<option value="{{ $opt->value }}" @if(isset($pro_specs[$spec->id]) && $pro_specs[$spec->id]->value == $opt->value)selected @endif>{{ $opt->name }}</option>
							@endforeach
						</select>
						@elseif ($spec->type == Specificant::OPTION_CHECKBOX)						
							@foreach ($spec->options as $opt)
							<input type="checkbox" name="specs[{{ $spec->id }}][]" value="{{ $opt->value }}"  @if(isset($pro_specs[$spec->id]) && in_array($opt->value, $pro_specs[$spec->id]->value))checked @endif>{{ $opt->name }}
							@endforeach
						@elseif ($spec->type == Specificant::OPTION_RADIO)
							@foreach ($spec->options as $opt)
							<input type="radio" name="specs[{{ $spec->id }}]" value="{{ $opt->value }}" @if(isset($pro_specs[$spec->id]) && $opt->value == $pro_specs[$spec->id]->value )checked @endif> {{ $opt->name }}
							@endforeach					
						@endif
                    	
                    </div>
                    @endforeach
                </div>
                
            </div><!-- /.box-body -->
            <div class="box-footer">
                <button class="btn btn-primary" type="submit">保存</button>
            </div>
            </form>
        </div><!-- /.box -->
    </div>
</div>
@stop
@section('end')
    @parent
{{ HTML::script("/ckeditor/ckeditor.js") }}
<script>
var init_cat_spec = $('#cat_spec').html();
var init_pro_cid = '{{ $pro->category_id }}';
$('#product_category').change(function(){
		var cid = $(this).val();
		if (!cid) {
			return;
		}
		if (cid == init_pro_cid) {
			$('#cat_spec').html(init_cat_spec);
			return;
		}
		var _url = "{{ route('admin.product.cat_spec',['id'=>':cat_id']) }}";
		var url = _url.replace(':cat_id', cid);
		
		$('#cat_spec').load(url);		
	});
$(function() {
			CKEDITOR.replace('product_introduct'	, {
						height: 250,
						extraPlugins: 'colorbutton,colordialog',
						filebrowserBrowseUrl : '/ckfinder/ckfinder.html',
						filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?Type=Images',
						filebrowserFlashBrowseUrl : '/ckfinder/ckfinder.html?Type=Flash',
						filebrowserUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
						filebrowserImageUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
						filebrowserFlashUploadUrl : '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
			});
});
</script>
@stop